<template>
  <div class="article-box">
    <van-nav-bar
      fixed
      placeholder
      title="文章详情"
      t
      left-arrow
      @click-left="$router.back()"
    />
    <h2>{{ detail.title }}</h2>
    <div class="avatar-box">
      <van-image round fit="cover" :src="detail.aut_photo" />
      <div class="info-box">
        <p>{{ detail.aut_name }}</p>
        <span>{{ $relvTime(detail.pubdate) }}</span>
      </div>
      <van-button round type="info" size="small">+ 关注</van-button>
    </div>
    <!-- 内容区域 -->
    <div class="content" v-html="detail.content"></div>
    <!-- 评论区域 -->
    <my-comment />
  </div>
</template>

<script>
import MyComment from './MyComment.vue'
import { articleDetailAPI } from '@/api/article'
export default {
  name: 'Detail',
  components: {
    MyComment
  },
  data () {
    return {
      detail: []
    }
  },
  async created () {
    const res = await articleDetailAPI(this.$route.params.id)
    // console.log(res)
    this.detail = res.data
  }
}
</script>

<style lang="less" scoped>
.article-box {
  h2 {
    font-size: 18px;
    margin: 15px;
  }
  .avatar-box {
    margin: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .van-image {
      width: 80px;
      height: 80px;
    }
    .info-box {
      margin-left: 10px;
      flex: 1;
      p {
        margin-bottom: 10px;
      }
      span {
        font-size: 12px;
        color: gray;
      }
    }
  }
  .content {
    padding: 0 15px;
    ::v-deep {
      img {
        width: 100%;
      }
      p {
        margin-left: 0 !important;
        width: 100%;
        word-break: break-all;
      }
      code,
      pre {
        background-color: #000;
        color: gray;
        width: 100%;
        display: inline-block;
        overflow: auto;
      }
    }
  }
}
</style>
